package pe.gob.mintra.mype.daoimpl;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;

import pe.gob.mintra.mype.bean.LimvdPeriodos;
import pe.gob.mintra.mype.dao.PeriodoDAO;
import pe.gob.mintra.mype.factory.MyBatisConnectionFactory;

public class PeriodoDAOImp implements PeriodoDAO{
	
	private final static Logger logPeriodoDAOImp = Logger.getLogger(PeriodoDAOImp.class);

	private SqlSessionFactory sqlSessionFactory;

	public PeriodoDAOImp() {
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}

	@Override
	public void insertarPeriodo(LimvdPeriodos objLimvdPeriodos) {
		SqlSession session = sqlSessionFactory.openSession();

		try {
			session.insert("LimvdPeriodos.insertarPeriodos",objLimvdPeriodos);
			session.commit();
		} 
		catch(Exception ex){
			session.rollback();
			logPeriodoDAOImp.error(ex.getMessage());
		}
		finally {
			session.close();
		}
		
	}

	@Override
	public void actualizarPeriodo(LimvdPeriodos objLimvdPeriodos) {
		SqlSession session = sqlSessionFactory.openSession();

		try {
			session.update("LimvdPeriodos.actualizarPeriodos",objLimvdPeriodos);
			session.commit();
		} 
		catch(Exception ex){
			session.rollback();
			logPeriodoDAOImp.error(ex.getMessage());
		}
		finally {
			session.close();
		}
		
	}

	

}
